package userandright

import (
	"gitee.com/tomatomeatman/golang-repository/bricks3/utils/ginutil"

	"github.com/gin-gonic/gin"
)

// @Controller 用户权限控制器
type UserAndRightController struct {
}

/**
 * 初始化
 */
func init() {
	controller := &UserAndRightController{}
	ginutil.AddUrl("/user/right/check/right", controller.CheckRight, ginutil.POST)
	ginutil.AddUrl("/user/right/find/rightid", controller.FindRightId, ginutil.POST)
	ginutil.AddUrl("/user/right/find/english", controller.FindEnglishByUserId, ginutil.POST)
}

// #region @Api {title=权限验证 explain=验证指定用户是否有访问指定url的权限(内部拦截器用)}
// @param {name=sUserId dataType=string paramType=query explain=用户编号 required=false}
// @param {name=url dataType=string paramType=query explain=权限值 required=true}
// @RequestMapping {name=FindByPage type=POST value=/user/right/check/right}
// #endregion
func (control UserAndRightController) CheckRight(ctx *gin.Context) (bool, string, interface{}) {
	sUserId := ginutil.GetParam(ctx, "sUserId", "").(string)
	url := ginutil.GetParam(ctx, "url", "").(string)

	return UserAndRightService{}.CheckRight(ctx, sUserId, url)
}

// #region @Api {title=查询用户权限 explain=根据用户查询用户所拥有的权限编号集合}
// @param {name=sUserId dataType=string paramType=query explain=用户编号 required=true}
// @RequestMapping {name=FindByPage type=POST value=/user/right/find/rightid}
// #endregion
func (control UserAndRightController) FindRightId(ctx *gin.Context) (bool, string, interface{}) {
	sUserId := ginutil.GetParam(ctx, "sUserId", "").(string)

	return UserAndRightService{}.FindRightId(sUserId)
}

// #region @Api {title=查询权限标识字符串 explain=根据用户取权限标识字符串(一个权限标识代表了多个可访问的url路径)}
// @param {name=sUserId dataType=string paramType=query explain=用户编号 required=true}
// @RequestMapping {name=FindByPage type=POST value=/user/right/find/english}
// #endregion
func (control UserAndRightController) FindEnglishByUserId(ctx *gin.Context) (bool, string, interface{}) {
	sUserId := ginutil.GetParam(ctx, "sUserId", "").(string)

	return UserAndRightService{}.FindEnglishByUserId(sUserId)
}
